package bishizhuanyong.网易;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
public class Main {

    //过了，厉害！
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] nums=new int[n];
        for (int i=0;i<n;i++){
            nums[i]=in.nextInt();
        }
        if (k==1){
            System.out.println(n);
            return;
        }
        Arrays.sort(nums);
        int max=nums[nums.length-1];
        int[] res=new int[nums.length];
        int maxcount=Integer.MIN_VALUE;
        HashMap<Integer,Integer> map=new HashMap<>();
        for (int i=0;i<nums.length;i++){
            map.put(nums[i],i);
        }
        for (int i=0;i<nums.length;i++){
            int cur=nums[i];
            for (int j=cur+k;j<=max;j=j+k){
                if (map.containsKey(j)) {
                    res[map.get(j)]++;
                    maxcount=Math.max(maxcount,res[map.get(j)]);
                }
            }
        }
        System.out.println(maxcount+1);
    }
}

/*
Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] nums=new int[n];
        for (int i=0;i<n;i++){
            nums[i]=in.nextInt();
        }
        if (k==1){
            System.out.println(n);
            return;
        }
        Arrays.sort(nums);
        int maxCount=0;
        for (int i=nums.length-1;i>=0;i--){
            int curCount=0;
            int j=i;
            while (j>=0&&nums[j]==nums[i]){
                j--;
                curCount++;
            }
            for (;j>=0;j--){
                if ((nums[i]-nums[j])%k==0)
                    curCount++;
            }
            maxCount=Math.max(maxCount,curCount);
        }
        System.out.println(maxCount);
 */
